package com.lkc.controller;

import com.lkc.bean.Users;
import com.lkc.service.UsersService;
import com.lkc.util.Page;
import com.lkc.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Member;

@RestController
@CrossOrigin//允许请求跨域访问
@RequestMapping("users")
public class UsersController {
    @Autowired
    UsersService usersService;

    @PostMapping
    public Result add(@RequestBody Users users) {
        Object obj = usersService.add(users);
        return Result.success(obj);
    }

    @PutMapping
    public Result edit(@RequestBody Users users) {
        Object obj = usersService.edit(users);
        return Result.success("编辑信息返回成功",obj);
    }

    @DeleteMapping("{id}")
    public Result del(@PathVariable("id") Integer id) {
        Object obj = usersService.del(id);
        return Result.success("删除成功",obj);
    }

    @GetMapping("{id}")
    public Result one(@PathVariable("id") Integer id) {
        Object obj = usersService.one(id);
        return Result.success(obj);
    }

    @GetMapping("all")
    public Result all(Users users) {
        Object obj = usersService.all(users);
        return Result.success(obj);
    }
    @GetMapping("page")
    public Result page(Page page, Users users){
        //查询一共有多少条数据
        //查询当前页要显示的数据
        //将以上数据封装到page对象里
        //返回page对象
    usersService.page(page,users);
    return Result.success(page);
    }
}
